/*******************************************************************************
 *
 * File Name:          DeletePropertyAction.java
 *
 * Created:            2007-9-19 下午07:25:01
 *
 * Original Author:    yu.peng
 *
 *------------------------------------------------------------------------------
 * MODIFICATION HISTORY
 *------------------------------------------------------------------------------
 * WHEN                WHO                 WHY
 * 2007-9-19 下午07:25:01 yu.peng             new
 *------------------------------------------------------------------------------
 *
 ******************************************************************************/
/*******************/
/* PACKAGE SECTION */
/*******************/
package org.njo.webapp.root.action.admin;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.njo.webapp.root.action.GenericAction;
import org.njo.webapp.root.model.activity.AppPropertyActivity;

/**
 * TODO:comment
 *
 * @author yu.peng
 * @version 0.01
 */
public class DeletePropertyAction extends GenericAction {

    // --------------------------------------------------------- Public Methods

    /**
     * Process the specified HTTP request, and create the corresponding HTTP
     * response (or forward to another web component that will create it).
     * Return an <code>ActionForward</code> instance describing where and how
     * control should be forwarded, or <code>null</code> if the response has
     * already been completed.
     *
     * @param mapping  The ActionMapping used to select this instance
     * @param form     The optional ActionForm bean for this request (if any)
     * @param request  The HTTP request we are processing
     * @param response The HTTP response we are creating
     * @throws Exception if the application business logic throws
     *                   an exception
     */
    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response) throws Exception {
        
        AppPropertyActivity appPropertyActivity = new AppPropertyActivity();
        String[] delProperties = request.getParameterValues("properties");
        
        // 验证输入
        if (delProperties==null || delProperties.length==0) {
            addMessage(request, new ActionMessage("error.admin.property.required"));
            return (new ActionForward("/processor.listproperty.tiles", false));
        }
        
        appPropertyActivity.removeProperties(delProperties);
        
        // TODO reset property
        
        return (new ActionForward("/processor.listproperty.tiles", false));
    }

}